<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <title>Kml</title>
    <style type="text/css">
        .editPane {
            position: absolute;
            right: 50px;
            top: 50px;
            text-align: center;
            background: #FFF;
            z-index: 1000;
            display: inline-block;

        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
    <div class='panel-heading'>
        <h5 class='panel-title text-center'>Kml</h5>
    </div>
    <div class='panel-body' id='params'>
        <p></p>
        <div align='center' class='button-group'>
            <input type='button' id='loadBt' class='btn btn-primary' data-i18n="[value]resources.btn_load" onclick="loadKml()"/>
        </div>
    </div>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, layer, loaded = false,
        host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    url = host + "/iserver/services/map-china400/rest/maps/China";
    map = new SuperMap.Map("map", {
        controls: [
            new SuperMap.Control.ScaleLine(),
            new SuperMap.Control.Zoom(),
            new SuperMap.Control.LayerSwitcher(),
            new SuperMap.Control.MousePosition(),
            new SuperMap.Control.OverviewMap(),
            new SuperMap.Control.Navigation({
                dragPanOptions: {
                    enableKinetic: true
                }
            })],
        projection: new SuperMap.Projection("EPSG:3857")
    });

    layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, {transparent: true}, {
        useCanvas: true,
        maxResolution: "auto"
    });
    layer.events.on({"layerInitialized": addLayer});

    function addLayer() {
        var center = new SuperMap.LonLat(0, 0);
        map.addLayer(layer);
        map.setCenter(center, 1);
    }

    function loadKml() {
        if (!loaded) {
            layer01 = new SuperMap.Layer.Vector("KML", {
                strategies: [new SuperMap.Strategy.Fixed()],
                protocol: new SuperMap.Protocol.HTTP({
                    url: host + "/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features.kml",   //"data/sichuang.kml",
                    format: new SuperMap.Format.KML({
                        extractStyles: true,
                        extractAttributes: true,
                        internalProjection: new SuperMap.Projection("EPSG:3857"),       //所在地图的坐标系
                        maxDepth: 2      //要解析外部链接文件时此值必须大于1
                    })
                })
            });
            map.addLayer(layer01);
            layer01.events.on({"featuresadded": featuresadd});
            loaded = true;
        }
    }

    function featuresadd() {
        var center = new SuperMap.LonLat(5000000, 8000000);
        map.setCenter(center, 1);
    }

</script>
</body>
</html>